﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAO
{
    public class UnitDao
    {
        public UnitDao()
        {
            new SqlHelper();
        }
        public bool insertUnit(string  name)
        {
            return SqlHelper.ExecuteNonQuery("INSERT_UNIT", CommandType.StoredProcedure,
                "@NAME", name);
        }

        public DataTable getUnits(string name)
        {
            return SqlHelper.ExecuteDataTable("GET_UNITS", CommandType.StoredProcedure,
                "@NAME", name);
        }

        public DataRow getUnitById(int id)
        {
            DataTable table = SqlHelper.ExecuteDataTable("GET_UNIT_BY_ID", CommandType.StoredProcedure,
                "@ID", id);
            if (table != null && table.Rows.Count > 0)
            {
                return table.Rows[0];
            }
            return null;
        }

        public bool updateUnit(int id, string name)
        {
            return SqlHelper.ExecuteNonQuery("UPDATE_UNIT", CommandType.StoredProcedure, "@ID", id, "@NAME", name);
        }

        public bool deleteUnit(int id)
        {
            return SqlHelper.ExecuteNonQuery("DELETE_UNIT", CommandType.StoredProcedure, "@ID", id);
        }


    }
}
